<?php

namespace app\api\command;
use app\common\model\Packages;
use fast\Random;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Kgjtongbu extends Command
{
    protected $model = null;

    protected function configure()
    {
        $this->setName('kgjtongbu')->setHelp('卡管家同步产品数据')->setDescription('卡管家同步产品数据');

    }

    protected function execute(Input $input, Output $output)
    {
        $data['goodsStatus'] = 'on_sale';
        $path = '/api/card/open/getGoodsList';
        $key  = config('site.kgj_appkey');
        $result = kgjcurl($path, $data,$key);
        if($result){
            foreach ($result['data'] as $k => $v) {
                $info = Packages::where(['packages_id' => $v['goodsCode'], 'platform_type' => 6])->find();
                if (!$info) {
                    for ($i = 2; $i <= 3; $i++) {
                        $inser['platform_type'] = 6;
                        $inser['packages_id']   = $v['goodsCode'];
                        $inser['name']          = $v['goodsSpac'];
                        $inser['user_name']     = $v['goodsName'];
                        $inser['type']          = $i;
                        $inser['is_selection']  = 2;
                        if ($v['operatorsType'] == 'telecom') {
                            $inser['cate_id'] = 1;
                        } elseif ($v['operatorsType'] == 'unicom') {
                            $inser['cate_id'] = 2;
                        } elseif ($v['operatorsType'] == 'cmcc') {
                            $inser['cate_id'] = 3;
                        }
                        $inser['photos']     = $v['goodsHeadImg'];
                        $inser['photoLists'] = $v['goodsDetail'];
                        $inser['data_json']  = json_encode($v, true);
                        Packages::create($inser);
                    }
                }else{
                    echo "无同步数据";
                }
            }
        }
    }
}
